<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import=" vn.edu.ptithcm.helper.CKEditorConfigHelper" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://ckeditor.com" prefix="ckeditor" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
<c:choose>
	<c:when test="${bean.cmd == 'add' }">
	   <spring:message  code="pim"/> - <spring:message  code="add.news"/>
	</c:when>
	<c:otherwise>
	   <spring:message  code="pim"/> - <spring:message  code="edit.news"/> - <c:out value="${news.title}"></c:out>
	</c:otherwise>
</c:choose>
</title>
<link href="<%= request.getContextPath() %>/css/custom.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/style.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/v.css" rel="stylesheet" type="text/css" />
<link href="<%= request.getContextPath() %>/css/jquery.ui.all.css" rel="stylesheet" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.6.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-ui-1.8.14.custom.js"></script>
<%@include file="script/pim-util.jsp" %>
<%@include file="script/news-script.jsp" %>
</head>
<body>
<% try{ %>
<c:if test="${bean.isSigned && bean.isAdmin}">
<div id="all">
<div id="wrapper">
<div id="mainheader">
	<jsp:include page="include/common/headerSignedIn.jsp" />
</div> 
<div id="content-wrapper">
<div id="top-menu">
    <jsp:include page="include/common/topMenuHome.jsp" /> 
</div>
<div class="main-content">
<form:form action="" method="post" commandName="news" acceptCharset="UTF-8" enctype="multipart/form-data">	   		  
<div>	
	<div class="v-row v-border-bottom" style="padding-top: 10px;">
		<div class="v-row-left" style="margin-left: 10px;">
			<span class="v-title">
				<c:choose>
					<c:when test="${bean.cmd == 'add' }">
					   <spring:message  code="add.news"/>
					</c:when>
					<c:otherwise>
					   <spring:message  code="edit.news"/>
					</c:otherwise>
				</c:choose>
			</span>
		</div>	
	</div>	
	
	<div class="v-body">
	
	<div class="v-row" id="v-global-message">
	   <c:if test="${addOK == true }">
	      	<span class="v-global-success-message v-row">
	      	    <span><spring:message  code="handle.add.news.success" /></span>
	      	</span>
	   </c:if>
	   <c:if test="${addOK == false }">
	      	<span class="v-global-error-message v-row">
	      	    <span><spring:message  code="handle.add.news.error" /></span>
	      	</span>
	    </c:if>
	    <c:if test="${editOK == true }">
	      	<span class="v-global-success-message v-row">
	      	    <span><spring:message  code="handle.edit.news.success" /></span>
	      	</span>
	   </c:if>
	   <c:if test="${editOK == false }">
	      	<span class="v-global-error-message v-row">
	      	    <span><spring:message  code="handle.edit.news.error" /></span>
	      	</span>
	    </c:if>
	</div>	
	
	<div style="margin-left: 20px;">
		<div class="v-row">
			<div class="v-row-left">
				<span class="v-required-title">
				    <spring:message code="title.required.field" />
				</span>
			</div>
		</div>	
			
		<div class="v-row">
			<div class="v-row-left">
				<span>
				    <spring:message code="title.required.news.title" />
				</span>
			</div>			
			<div class="v-row-right eighty">			    				                      
				<span>
				    <form:input path="title" maxlength="100" cssClass="v-input"/>		
				 </span>				
				<form:errors path="title" cssClass="v-error-message" />							
			</div>
		</div>					
		
		<div class="v-row">
			<div class="v-row-left">
				<span>
				    <spring:message code="title.required.news.type" />
				</span>
			</div>			
			<div class="v-row-right eighty">			    
				  <span>
                     <form:select path="type" cssClass="v-select">
                        <form:option value=""><spring:message code="please.choice" /></form:option>                                              
                        <form:option value="announcement"><spring:message code="news.type.announcement" /></form:option>
                        <form:option value="upcomingevent"><spring:message code="marriedstatus.upcomingevent" /></form:option> 
                        <form:option value="other"><spring:message code="marriedstatus.other" /></form:option>                            
                     </form:select>				    
				 </span>
				 <form:errors path="type" cssClass="v-error-message" />					 							
			</div>
		</div>	
		
		<div class="v-row">
			<div class="v-row-left">
				<span>
			     	<spring:message code="title.required.news.description" />
				</span>
			</div>			
			<div class="v-row-right eighty">			   
				<span>
				    <form:textarea cols="88" rows="8" path="description"/>		
				 </span>
				 <br/>
				<form:errors path="description" cssClass="v-error-message" />				
			</div>
		</div>	
		
		<div class="v-row">
			<div class="v-row-left">
				<span>
			     	<spring:message code="title.required.news.content" />
				</span>
			</div>			
			<div class="v-row-right eighty">			   
				<span>
				    <form:textarea cols="88" rows="8" path="content"/>		
				 </span>
				 <br/>
				<form:errors path="content" cssClass="v-error-message" />				
			</div>
		</div>			        				
		
		<div class="v-row">
			<div class="v-row-left">
			   <span><spring:message code="project.logourl" /></span>			   
			</div>			
			<div class="v-row-right eighty">											
				<span>
					<input class="v-input" type="file" id="imageurl" name="imageurl" 
					       onchange="imagePreview('imageurl', 'image-preview')" size="46"/>
				</span>					
				<br/>
				<form:errors path="imageurl" cssClass="v-error-message" />									
			</div>
		</div>
			
		<div class="v-row">
		  <div class="v-row-left" style="border: thin ridge #E0EDF4;">					
				<div class="new-manage-org-logo-org">	
				   <c:choose>
				   <c:when test="${addOK == true || bean.cmd == 'edit' }">	
				      <c:set value="articleDetail.htm?id=${news.newsid}" var="url"></c:set>   			    				        				     
					  <a href="${url}">					      				      			     
					  <c:set var="smallImageUrl" value="${news.imageurl}" />
					  <c:choose>
							<c:when test="${smallImageUrl == null || smallImageUrl == '' }">
								<img id="image-preview"  alt="" src="<%=request.getContextPath()%>/images/small_noImage.gif" 
								     onLoad='scaleImg(this, 80, 80)' />
							</c:when>							
							<c:otherwise>
								<img id="image-preview" alt="" src='<c:out value="${smallImageUrl}"></c:out>' 
								     onLoad='scaleImg(this, 80, 80)'>
							</c:otherwise>
					  </c:choose>
					   </a>					  
				   </c:when>
				   <c:otherwise>
				        <img id="image-preview"  alt="" src="<%=request.getContextPath()%>/images/small_noImage.gif" 
						     onLoad='scaleImg(this, 80, 80)' />
				   </c:otherwise>
				   </c:choose>					
				</div>				
		  </div>
		  <div class="v-row-right eighty">		    		  
		     <span class="v-info"><spring:message code="warning.news.logo" /></span>		   
		  </div>
		</div>
		
		<div class="v-row">
		    <br/>
			<div class="v-row-center">
				<span>
				<input type="submit" class="bt-form" 
					        value="<spring:message code="button.save" />" />
				</span>				
				<span>
				<input type="button" class="bt-form"
						onclick="cancel('<c:out value='${bean.returnToFullPageURL }'/>')"
						value="<spring:message code="button.cancel"/>" />
				</span>
			</div>
		</div>
	</div>
</div>
</div>
<input type="hidden" name="cmd" value="${bean.cmd}"/>
<input type="hidden" name="returnToFullPageURL" value="${bean.returnToFullPageURL}"/>
</form:form>	 	
</div>	
</div>
</div>
<div class="footer">
	<jsp:include page="include/common/footer.jsp" />
</div>
</div>			   
<ckeditor:replace basePath="/ckeditor/" replace="content" config="<%= CKEditorConfigHelper.createConfig(725) %>"/>
</c:if>
<% } catch(RuntimeException re){ re.printStackTrace(); } %>
</body>
</html>	